package com.jxw.studyrecordprovider;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

/* loaded from: classes.dex */
public class StudyRecorderProvider extends ContentProvider {
    public static final String AUTHORITY = "com.jxw.studyrecord.provider";
    public static final String PATH = "studyrecorder";
    public static final int STUDY_RECORDR = 1;
    public static final String STUDY_RECORDR_CONTENT_ITEM = "vnd.android.cursor.item/vnd.studyrecorder.studyrecorder";
    public static final String STUDY_RECORDR_CONTENT_TYPE = "vnd.android.cursor.dir/vnd.studyrecorder.studyrecorder";
    public static final int STUDY_RECORDR_ID = 2;
    public static final Uri STUDY_RECORDR_URI = Uri.parse("content://com.jxw.studyrecord.provider/studyrecorder");
    private static UriMatcher urimatcher = new UriMatcher(-1);
    private DbOpenHelper dbOpenHelper;

    static {
        urimatcher.addURI(AUTHORITY, PATH, 1);
        urimatcher.addURI(AUTHORITY, "studyrecorder/#", 2);
    }

    @Override // android.content.ContentProvider
    public boolean onCreate() {
        this.dbOpenHelper = new DbOpenHelper(getContext());
        return false;
    }

    @Override // android.content.ContentProvider
    public String getType(Uri uri) {
        int match = urimatcher.match(uri);
        if (match != 1) {
            if (match == 2) {
                return STUDY_RECORDR_CONTENT_ITEM;
            }
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        return STUDY_RECORDR_CONTENT_TYPE;
    }

    @Override // android.content.ContentProvider
    public int delete(Uri uri, String str, String[] strArr) {
        int delete;
        SQLiteDatabase writableDatabase = this.dbOpenHelper.getWritableDatabase();
        int match = urimatcher.match(uri);
        if (match == 1) {
            delete = writableDatabase.delete(DbOpenHelper.TABLENAME, str, strArr);
        } else if (match == 2) {
            delete = writableDatabase.delete(DbOpenHelper.TABLENAME, str, strArr);
        } else {
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        writableDatabase.close();
        return delete;
    }

    @Override // android.content.ContentProvider
    public Uri insert(Uri uri, ContentValues contentValues) {
        SQLiteDatabase readableDatabase = this.dbOpenHelper.getReadableDatabase();
        int match = urimatcher.match(uri);
        if (match == 1) {
            long insert = readableDatabase.insert(DbOpenHelper.TABLENAME, "", contentValues);
            if (insert > 0) {
                Uri withAppendedId = ContentUris.withAppendedId(STUDY_RECORDR_URI, insert);
                getContext().getContentResolver().notifyChange(withAppendedId, null);
                return withAppendedId;
            }
        } else if (match == 2) {
            long insert2 = readableDatabase.insert(DbOpenHelper.TABLENAME, "", contentValues);
            if (insert2 > 0) {
                Uri withAppendedId2 = ContentUris.withAppendedId(STUDY_RECORDR_URI, insert2);
                getContext().getContentResolver().notifyChange(withAppendedId2, null);
                return withAppendedId2;
            }
        } else {
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        return null;
    }

    @Override // android.content.ContentProvider
    public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        SQLiteDatabase readableDatabase = this.dbOpenHelper.getReadableDatabase();
        int match = urimatcher.match(uri);
        if (match != 1) {
            if (match == 2) {
                return readableDatabase.query(DbOpenHelper.TABLENAME, strArr, str, strArr2, null, null, str2);
            }
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        return readableDatabase.query(DbOpenHelper.TABLENAME, strArr, str, strArr2, null, null, str2);
    }

    @Override // android.content.ContentProvider
    public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) {
        SQLiteDatabase writableDatabase = this.dbOpenHelper.getWritableDatabase();
        int match = urimatcher.match(uri);
        if (match != 1) {
            if (match == 2) {
                return writableDatabase.update(DbOpenHelper.TABLENAME, contentValues, str, strArr);
            }
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        return writableDatabase.update(DbOpenHelper.TABLENAME, contentValues, str, strArr);
    }
}
